-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Allow passing expr
metavariable to cfg
#146961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_attr_parsing |
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
This comment has been minimized.
This comment has been minimized.
} | ||
|
||
pass_nonterminal!(n!()); | ||
//~^ ERROR expected one of `(`, `::`, or `=`, found `!` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is surprisingly different from what you get when "inlining" the macro?
error: expected unsuffixed literal, found `!`
--> src/main.rs:6:15
|
6 | #[repr(align(n!()))]
| ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$expr
effectively has parentheses around it, so the "inlined" version would look more like #[repr(align((n!())))]
.
1cd49c1
to
10f76de
Compare
Just as an update, after #124141 we effectively no longer have nonterminal tokens in the grammar (*). I hoped that some time after #124141 either @nnethercote or me relax these rules in many cases, when there are no backward compatibility concerns at least, and pass the change through lang team, but it didn't happen yet. A number of current hacks like accepting @Jules-Bertholet You could very well start the same process, just from a different point and accept any token streams that look like cfg predicates as cfg predicates, from any matchers, not just (*) Or we technically have, but only for compatibility and to avoid extending the language without the lang team process. |
As for the current implementation, the new |
This seems reasonable to me. It allows all @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
@rfcbot reviewed |
@rfcbot reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Happy to see a more general version of this, if we can. |
@rfcbot reviewed I am in favor of making the "special tokens" and invisible delimiters less visible to the user. |
This PR allows expanding
expr
metavariables inside the configuration predicates ofcfg
andcfg_attr
invocations.For example, the following code will now compile:
There is currently no
macro_rules
fragment specifier that can represent all validcfg
predicates.meta
comes closest, but excludestrue
andfalse
. By fixing that, this change makes it easier to write declarative macros that parsecfg
orcfg_attr
invocations, for example #146281.@rustbot label T-lang needs-fcp A-attributes A-cfg A-macros